//
//  ZYHelpCenterVC.m
//  YiLin
//
//  Created by Zyark on 2018/6/11.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYHelpCenterVC.h"
#import "ZYHelpCenterDetailVC.h"

@interface ZYHelpCenterVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) NSArray *titleArray;
@end

@implementation ZYHelpCenterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.title = [[ZYChangeLanguage sharedZYChangeLanguage] getStringByKey:LC_ME_MAIN_HELP_CENTER];
}

#pragma mark - init
-(void)setup{
    [self setupView];
}

-(void)setupView{
    [self setupTableView];
}

-(void)setupTableView{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ZYSCREEN_W, ZYSCREEN_H - self.navigationView.bottom)];
    [self.view addSubview:_tableView];
    _tableView.top = self.navigationView.bottom;
    _tableView.centerX = self.view.centerX;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.scrollEnabled = NO;
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_tableView reloadData];
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

#pragma mark - TableViewDelegate datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.titleArray count];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(ZYiPhone5_OR_5c_OR_5s || ZYiPhone4_OR_4s){
        return 35;
    }if(ZYiPhone6Plus_OR_6sPlus){
        return 50;
    }
    return 45;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
    }
    //    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    cell.backgroundColor = [UIColor whiteColor];
    cell.textLabel.text = self.titleArray[indexPath.row];
    if(indexPath.row == 0){
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.textColor = kMainColor;
        cell.textLabel.font = [UIFont systemFontOfSize:18];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }else{
        cell.textLabel.textColor = kLabelColor;
        cell.textLabel.font = [UIFont systemFontOfSize:16];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    return cell;
}

#pragma mark - TableView delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if(indexPath.row == 0){
        return;
    }
    NSInteger index = indexPath.row - 1;
    ZYHelpCenterDetailVC *vc = [[ZYHelpCenterDetailVC alloc] init];
    vc.problemTitle = [self.titleArray objectAtIndex:indexPath.row];
    vc.problemType = index;
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark - Getter
-(NSArray *)titleArray{
    if(!_titleArray){
        ZYChangeLanguage *language = [ZYChangeLanguage sharedZYChangeLanguage];
        _titleArray = @[[language getStringByKey:LC_HELP_CENTER_TEXT_COMMON_PROBLEM],[NSString stringWithFormat:@"%@?",[language getStringByKey:LC_HELP_CENTER_TEXT_INTERNET_ERROR]],
                        [NSString stringWithFormat:@"%@?",[language getStringByKey:LC_HELP_CENTER_TEXT_DEVICE_ERROR]],
                        [language getStringByKey:LC_HELP_CENTER_TEXT_APP_ERROR]];
    }
    return _titleArray;
}

@end
